package com.we823.cms.controller.manage;

import org.apache.commons.lang3.StringUtils;

import com.we823.cms.core.security.shiro.PermissionList;
import com.we823.cms.core.security.shiro.PermissionStatus;

public abstract class SecurityBaseController {
	public PermissionList permissionList = null;

	/**
	 * 权限前缀：如sys:user 则生成的新增权限为 sys:user:create
	 */
	public void setResourceIdentity(String resourceIdentity) {
		if (!StringUtils.isEmpty(resourceIdentity)) {
			permissionList = PermissionList.newPermissionList(resourceIdentity);
		}
	}

	public void check(PermissionStatus permissionStatus) {
		if (permissionList != null) {
			switch (permissionStatus) {
			case CREATE:
				permissionList.assertHasCreatePermission();
				break;
			case UPDATE:
				permissionList.assertHasUpdatePermission();
				break;
			case DELETE:
				permissionList.assertHasDeletePermission();
				break;
			case VIEW:
				permissionList.assertHasViewPermission();
				break;
			default:
				permissionList.assertHasCreatePermission();
				permissionList.assertHasUpdatePermission();
				permissionList.assertHasDeletePermission();
				permissionList.assertHasViewPermission();
				break;
			}
		}
	}

	/**
	 * 设置权限名称
	 */
	public abstract void setIndetity();
}
